<?php
/*
 * @Author: your name2
 * @Date: 2021-09-21 16:46:35
 * @LastEditTime: 2022-01-25 15:27:29
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /nlog/app/Http/Controllers/AdminController/Login.php
 */

namespace App\Http\Controllers\crm;


use Illuminate\Support\Facades\Request;
use App\Models\crm_model\CrmProduct as CrmProductDb;                        // admins表

class CrmProduct extends BaseController
{

    public function productAdd()
    {
        return    redis_mysql_add('crm_product');
    }

    public function productEdit()
    {
        return    redis_mysql_edit('crm_product');
    }


    public function productSelOne()
    {
        return    redis_mysql_selone('crm_product');
    }

    public function productList()
    {
        // if(Request::has('division_id')){
            $whereStr = '';
            $limitStr = '';
            $division_id =  Request::has('division_id')? Request::input('division_id'):$this->getAdminInfo()['division_id'];
            if (Request::input('pageSize') && Request::input('page')) {
                $limitStr =   limit_joint(Request::input('page'), Request::input('pageSize'));
            }
            if(Request::has('keyWord')){

            $keyWord = array_filter(Request::input('keyWord'), 'filtrfunction');
            if(isset($keyWord['manyField'])){
                $whereStr .= havaWhereLikeManyField($keyWord['manyField']);
                unset($keyWord['manyField']);
            }
            if (!empty($keyWord)) {
                $whereStr .= havaWhereLikeJoinEqual($keyWord);
            }
        }

            $list  =  CrmProductDb::crmProductList( $division_id ,$whereStr, $limitStr);
            $count =  CrmProductDb::crmProductCount($division_id ,$whereStr);
            return $this->create(200,'查询成功',['list'=>$list,'total'=>$count[0]['count']]);
       

    }
}
